<template>
  <div class="p-2 page-flex">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
      :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="区域" prop="region">
              <el-cascader v-model="queryParams.region" :options="searchRegionOptions"
                :props="{ lazy: true, lazyLoad: loadRegion, value: 'value', label: 'label', checkStrictly: true }"
                placeholder="请选择区域" style="width: 240px" clearable />
            </el-form-item>
            <el-form-item label="客户类型" prop="clientType">
              <el-select v-model="queryParams.clientType" placeholder="请选择客户类型" clearable>
                <el-option v-for="dict in pro_client_type" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="对接人员" prop="jointBy">
              <el-select
                :model-value="selectedSearchJoint ? selectedSearchJoint.userName || selectedSearchJoint.nickName : ''"
                placeholder="请选择对接人员" style="width: 240px" clearable @click="showSearchJointSelector = true"
                @clear="clearSearchJoint">
                <template #empty>
                  <div style="text-align: center; padding: 10px">
                    <el-button type="primary" plain @click="showSearchJointSelector = true"> 选择对接人员 </el-button>
                  </div>
                </template>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never" class="table-card">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd"
              v-hasPermi="['project:proClientMaintain:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()"
              v-hasPermi="['project:proClientMaintain:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
              v-hasPermi="['project:proClientMaintain:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport"
              v-hasPermi="['project:proClientMaintain:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="proClientMaintainList" @selection-change="handleSelectionChange" border
        class="flex-table">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="主键" align="center" prop="id" v-if="false" />
        <el-table-column label="填报人" align="center" prop="recordName" />
        <el-table-column label="填报日期" align="center" prop="recordTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.recordTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="区域" align="center" prop="regionName" show-overflow-tooltip />
        <el-table-column label="客户类型" align="center" prop="clientType">
          <template #default="scope">
            <dict-tag :options="pro_client_type" :value="scope.row.clientType" />
          </template>
        </el-table-column>
        <el-table-column label="工作汇报情况" align="center" prop="workCase" :show-overflow-tooltip="true" />
        <el-table-column label="对接人" align="center" prop="jointName" />
        <el-table-column label="审核状态" align="center" width="120" prop="auditStatus">
          <template #default="scope">
            <dict-tag :options="approval_commit_status" :value="scope.row.auditStatus" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
          <template #default="scope">
            <el-tooltip content="查看详情" placement="top">
              <el-button link type="primary" icon="View" @click="handleView(scope.row)"
                v-hasPermi="['project:proClientMaintain:query']"></el-button>
            </el-tooltip>
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['project:proClientMaintain:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)"
                v-hasPermi="['project:proClientMaintain:remove']"></el-button>
            </el-tooltip>
            <el-tooltip content="提交审核" placement="top">
              <el-button link type="success" icon="Upload" @click="handleSubmitAudit(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination class="pagination-fixed" v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改客户维护对话框 -->
    <el-dialog :title="dialog.title" :model-value="dialog.visible" @update:model-value="(val) => (dialog.visible = val)"
      width="900px" append-to-body>
      <template #default>
        <div style="padding-right: 24px">
          <el-form ref="proClientMaintainFormRef" :model="form" :rules="rules" label-width="120px" label-position="left"
            style="padding: 20px 0 20px 24px">
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="填报人" prop="recordBy">
                  <el-input :value="form.recordName || userStore.name" readonly style="width: 100%" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="填报日期" prop="recordTime">
                  <el-date-picker clearable v-model="form.recordTime" type="date" value-format="YYYY-MM-DD"
                    placeholder="请选择填报日期" style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="区域" prop="region">
                  <el-cascader v-model="form.region" :options="regionOptions"
                    :props="{ lazy: true, lazyLoad: loadRegion, value: 'value', label: 'label', checkStrictly: true }"
                    :placeholder="regionPlaceholder" style="width: 100%" clearable />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="客户类型" prop="clientType">
                  <el-select v-model="form.clientType" placeholder="请选择客户类型" style="width: 100%">
                    <el-option v-for="dict in pro_client_type" :key="dict.value" :label="dict.label"
                      :value="dict.value"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="工作汇报情况" prop="workCase">
                  <el-input v-model="form.workCase" type="textarea" :rows="4" placeholder="请输入工作汇报情况"
                    style="width: 100%" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="附属文件" prop="file">
                  <file-upload v-model="form.file" style="width: 100%" :file-size="256" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="对接人" prop="jointBy">
                  <div class="user-selector-container">
                    <div class="selected-users" v-if="selectedJoints.length > 0">
                      <el-tag v-for="user in selectedJoints" :key="user.userId" closable @close="removeJoint(user)"
                        type="primary" style="margin-right: 8px; margin-bottom: 4px">
                        {{ user.userName || user.nickName }}
                      </el-tag>
                    </div>
                    <el-button type="primary" plain @click="openJointSelector" style="width: 100%">
                      {{ selectedJoints.length > 0 ? '重新选择对接人' : '选择对接人' }}
                    </el-button>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" :rows="4" placeholder="请输入备注" style="width: 100%" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </template>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm"
            style="font-size: 16px; min-width: 100px">确 定</el-button>
          <el-button @click="cancel" style="font-size: 16px; min-width: 100px">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 查看详情对话框 -->
    <el-dialog :title="viewDialog.title" :model-value="viewDialog.visible"
      @update:model-value="(val) => (viewDialog.visible = val)" width="900px" append-to-body>
      <template #default>
        <div style="padding-right: 24px">
          <el-form ref="proClientMaintainFormRef" :model="form" label-width="120px" label-position="left"
            style="padding: 20px 0 20px 24px">
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="填报人">
                  <el-input :value="form.recordName || userStore.name" readonly style="width: 100%" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="填报日期">
                  <el-date-picker v-model="form.recordTime" type="date" value-format="YYYY-MM-DD" placeholder="请选择填报日期"
                    style="width: 100%" readonly disabled>
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="区域">
                  <el-cascader v-model="form.region" :options="regionOptions"
                    :props="{ lazy: true, lazyLoad: loadRegion, value: 'value', label: 'label', checkStrictly: true }"
                    :placeholder="regionPlaceholder" style="width: 100%" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="客户类型">
                  <el-select v-model="form.clientType" placeholder="请选择客户类型" style="width: 100%" disabled>
                    <el-option v-for="dict in pro_client_type" :key="dict.value" :label="dict.label"
                      :value="dict.value"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="工作汇报情况">
                  <el-input v-model="form.workCase" type="textarea" :rows="4" placeholder="请输入工作汇报情况"
                    style="width: 100%" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="附属文件">
                  <file-upload v-model="form.file" style="width: 100%" :file-size="256" :disabled="true" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="对接人">
                  <div class="user-selector-container">
                    <div class="selected-users" v-if="selectedJoints.length > 0">
                      <el-tag v-for="user in selectedJoints" :key="user.userId" type="primary"
                        style="margin-right: 8px; margin-bottom: 4px">
                        {{ user.userName || user.nickName }}
                      </el-tag>
                    </div>
                    <el-input v-if="selectedJoints.length === 0" value="暂无对接人" readonly style="width: 100%" />
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注">
                  <el-input v-model="form.remark" type="textarea" :rows="4" placeholder="请输入备注" style="width: 100%"
                    readonly />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </template>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancelView" style="font-size: 16px; min-width: 100px">关 闭</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 对接人选择器 -->
    <UserSelector v-model:visible="showJointSelector" title="选择对接人" :selected-user-ids="form?.jointBy"
      :selected-user-names="form?.jointName" :multiple="true" @confirmWithIds="confirmJointSelector"
      @cancel="cancelJointSelector" />

    <!-- 搜索条件用的对接人员选择器 -->
    <UserSelector v-model:visible="showSearchJointSelector" title="选择对接人员" :selected-user-ids="queryParams?.jointBy"
      :selected-user-names="selectedSearchJointName" :multiple="false" @confirmWithIds="handleSearchJointConfirm"
      @cancel="handleSearchJointCancel" />

    <!-- 审核流程组件 -->
    <ApprovalFlow v-model:visible="approvalFlowVisible" :business-type="businessType"
      :business-id="currentClientMaintainForApproval?.id"
      :title="`客户维护审核-${currentClientMaintainForApproval?.regionName || ''}`" @confirm="handleApprovalConfirm"
      @cancel="handleApprovalCancel" />
  </div>
</template>

<script setup name="ProClientMaintain" lang="ts">
import { listProClientMaintain, getProClientMaintain, delProClientMaintain, addProClientMaintain, updateProClientMaintain } from '@/api/project/client/maintain';
import { ProClientMaintainVO, ProClientMaintainQuery, ProClientMaintainForm } from '@/api/project/client/maintain/types';
import { useUserStore } from '@/store/modules/user';
import { getToday } from '@/utils/dateUtils';
import { listAddressByParent } from '@/api/project/init/address';
import UserSelector from '@/components/UserSelector/index.vue';
import ApprovalFlow from '@/components/ApprovalFlow/index.vue';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { pro_client_type, approval_commit_status } = toRefs<any>(proxy?.useDict('pro_client_type', 'approval_commit_status'));

const userStore = useUserStore();

// 项目区域级联选择相关
const regionOptions = ref([]);
const regionPlaceholder = ref('请选择区域');

// 搜索条件区域选择相关
const searchRegionOptions = ref([]);

// 对接人选择相关
const showJointSelector = ref(false);
const selectedJoints = ref([]);

// 搜索条件对接人员选择相关
const showSearchJointSelector = ref(false);
const selectedSearchJoint = ref(null);
const selectedSearchJointName = ref('');

const proClientMaintainList = ref<ProClientMaintainVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const proClientMaintainFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

// 查看详情对话框状态
const viewDialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: ProClientMaintainForm = {
  id: undefined,
  recordName: undefined,
  recordTime: undefined,
  region: '',
  regionName: undefined,
  clientType: undefined,
  workCase: undefined,
  file: undefined,
  remark: undefined,
  recordBy: undefined,
  jointBy: undefined,
  jointName: undefined,
}
const data = reactive<PageData<ProClientMaintainForm, ProClientMaintainQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    region: undefined,
    clientType: undefined,
    jointBy: undefined,
    params: {
    }
  },
  rules: {
    recordBy: [
      { required: true, message: "填报人不能为空", trigger: "change" }
    ],
    recordTime: [
      { required: true, message: "填报日期不能为空", trigger: "change" }
    ],
    region: [
      { required: true, message: "区域不能为空", trigger: "change" }
    ],
    clientType: [
      { required: true, message: "客户类型不能为空", trigger: "change" }
    ],
    workCase: [
      { required: true, message: "工作汇报情况不能为空", trigger: "blur" }
    ],
    file: [
      { required: true, message: "附属文件不能为空", trigger: "change" }
    ],
    jointBy: [
      { required: true, message: "对接人不能为空", trigger: "change" }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询客户维护列表 */
const getList = async () => {
  loading.value = true;
  try {
    const params = { ...queryParams.value };
    // 处理区域参数
    if (params.region && Array.isArray(params.region)) {
      params.region = params.region.join(',');
    }
    const res = await listProClientMaintain(params);
    proClientMaintainList.value = res.rows;
    total.value = res.total;
  } catch (error) {
    console.error('获取列表失败:', error);
    proxy?.$modal.msgError('获取列表失败');
  } finally {
    loading.value = false;
  }
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}

/** 关闭查看详情对话框 */
const cancelView = () => {
  reset();
  viewDialog.visible = false;
}

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  selectedJoints.value = [];
  proClientMaintainFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  queryParams.value.params = {};
  // 重置查询参数中的区域字段
  queryParams.value.region = undefined;
  // 重置搜索条件对接人员选择
  selectedSearchJoint.value = null;
  selectedSearchJointName.value = '';
  queryParams.value.jointBy = undefined;
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: ProClientMaintainVO[]) => {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

// 区域数据加载
const loadRegion = async (node, resolve) => {
  try {
    // 确保 parentId 是有效的数字，默认为 0
    let parentId = 0;
    if (node && typeof node.value === 'number') {
      parentId = node.value;
    } else if (node && node.value !== undefined && node.value !== null) {
      const parsed = parseInt(String(node.value), 10);
      if (!isNaN(parsed)) {
        parentId = parsed;
      }
    }

    const res = await listAddressByParent(parentId);
    const data = res.data || [];
    resolve(
      data.map((item) => ({
        value: item.id,
        label: item.name,
        leaf: false
      }))
    );
  } catch (error) {
    console.error('加载区域数据失败:', error);
    resolve([]);
  }
};

// 顶部搜索也复用 loadRegion 以避免重复逻辑

// 对接人选择相关方法
const openJointSelector = () => {
  showJointSelector.value = true;
};

const confirmJointSelector = (data) => {
  if (data.users && data.users.length > 0) {
    selectedJoints.value = [...data.users];

    if (form.value) {
      form.value.jointBy = data.userIds || '';
      form.value.jointName = data.userNames || '';
    }
  } else {
    selectedJoints.value = [];
    if (form.value) {
      form.value.jointBy = '';
      form.value.jointName = '';
    }
  }

  showJointSelector.value = false;
};

const cancelJointSelector = () => {
  showJointSelector.value = false;
};

const removeJoint = (joint) => {
  const newJoints = selectedJoints.value.filter((j) => j.userId !== joint.userId);
  selectedJoints.value = newJoints;

  if (form.value) {
    const userIds = newJoints.map((user) => user.userId);
    const userNames = newJoints.map((user) => user.userName || user.nickName);

    form.value.jointBy = userIds.length > 0 ? userIds.join(',') : '';
    form.value.jointName = userNames.length > 0 ? userNames.join(',') : '';
  }
};

// 搜索条件对接人员选择相关方法
const handleSearchJointConfirm = (data) => {
  if (data.users && data.users.length > 0) {
    selectedSearchJoint.value = data.users[0];
    selectedSearchJointName.value = data.userNames || '';

    if (queryParams.value) {
      queryParams.value.jointBy = data.userIds || '';
    }
  } else {
    selectedSearchJoint.value = null;
    selectedSearchJointName.value = '';
    if (queryParams.value) {
      queryParams.value.jointBy = '';
    }
  }

  showSearchJointSelector.value = false;
};

const handleSearchJointCancel = () => {
  showSearchJointSelector.value = false;
};

const clearSearchJoint = () => {
  selectedSearchJoint.value = null;
  selectedSearchJointName.value = '';
  if (queryParams.value) {
    queryParams.value.jointBy = '';
  }
};

// 审核流程相关
const approvalFlowVisible = ref(false);
const currentClientMaintainForApproval = ref<any>(null);
const businessType = ref('CLIENT-MAINTAIN-AUDIT');

/**
 * 提交客户维护审核
 */
const handleSubmitAudit = (row: any) => {
  if (!row.id) {
    ElMessage.error('客户维护记录ID不能为空');
    return;
  }

  currentClientMaintainForApproval.value = {
    id: row.id,
    regionName: row.regionName || '客户维护'
  };
  approvalFlowVisible.value = true;
};

/**
 * 审核流程确认回调
 */
const handleApprovalConfirm = async () => {
  try {
    ElMessage.success('审核流程提交成功');
    approvalFlowVisible.value = false;
    currentClientMaintainForApproval.value = null;
    // 刷新列表
    await getList();
  } catch (error) {
    console.error('审核流程提交失败:', error);
    ElMessage.error('审核流程提交失败');
  }
};

/**
 * 审核流程取消回调
 */
const handleApprovalCancel = () => {
  approvalFlowVisible.value = false;
  currentClientMaintainForApproval.value = null;
};

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  form.value.recordTime = getToday();
  form.value.recordBy = Number(userStore.userId);
  form.value.region = '';
  dialog.visible = true;
  dialog.title = "添加客户维护";
}

/** 修改按钮操作 */
const handleUpdate = async (row?: ProClientMaintainVO) => {
  reset();
  const _id = row?.id || ids.value[0]
  const res = await getProClientMaintain(_id);
  Object.assign(form.value, res.data);

  // 设置对接人信息 - 支持多个用户
  if (res.data.jointBy && res.data.jointName) {
    const userIds = res.data.jointBy.split(',').filter(id => id.trim());
    const userNames = res.data.jointName.split(',').filter(name => name.trim());

    selectedJoints.value = userIds.map((userId, index) => ({
      userId: userId.trim(),
      nickName: userNames[index] ? userNames[index].trim() : '',
      userName: userNames[index] ? userNames[index].trim() : ''
    }));
  }

  dialog.visible = true;
  dialog.title = "修改客户维护";
}

/** 查看详情按钮操作 */
const handleView = async (row?: ProClientMaintainVO) => {
  reset();
  const _id = row?.id || ids.value[0]
  const res = await getProClientMaintain(_id);
  Object.assign(form.value, res.data);

  // 设置对接人信息 - 支持多个用户
  if (res.data.jointBy && res.data.jointName) {
    const userIds = res.data.jointBy.split(',').filter(id => id.trim());
    const userNames = res.data.jointName.split(',').filter(name => name.trim());

    selectedJoints.value = userIds.map((userId, index) => ({
      userId: userId.trim(),
      nickName: userNames[index] ? userNames[index].trim() : '',
      userName: userNames[index] ? userNames[index].trim() : ''
    }));
  }

  viewDialog.visible = true;
  viewDialog.title = "查看客户维护详情";
}

/** 提交按钮 */
const submitForm = () => {
  proClientMaintainFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      try {
        const formData = { ...form.value };
        // 处理区域参数
        if (formData.region && Array.isArray(formData.region)) {
          formData.region = formData.region.join(',');
        }

        if (formData.id) {
          await updateProClientMaintain(formData);
        } else {
          await addProClientMaintain(formData);
        }
        proxy?.$modal.msgSuccess("操作成功");
        dialog.visible = false;
        await getList();
      } catch (error) {
        console.error('提交失败:', error);
        proxy?.$modal.msgError('操作失败，请重试');
      } finally {
        buttonLoading.value = false;
      }
    }
  });
}

/** 删除按钮操作 */
const handleDelete = async (row?: ProClientMaintainVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除客户维护编号为"' + _ids + '"的数据项？').finally(() => loading.value = false);
  await delProClientMaintain(_ids);
  proxy?.$modal.msgSuccess("删除成功");
  await getList();
}

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download('pro/client/maintain/export', {
    ...queryParams.value
  }, `proClientMaintain_${new Date().getTime()}.xlsx`)
}

// 监听区域名称变化
watch(
  () => [form.value.regionName, dialog.visible],
  ([name, visible]) => {
    if (visible) {
      regionPlaceholder.value = (typeof name === 'string' ? name : '') || '请选择区域';
    }
  },
  { immediate: true }
);

onMounted(() => {
  getList();
});

</script>

<style scoped>
/* 页面弹性布局 */
.page-flex {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 16px);
}

.table-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.table-card :deep(.el-card__body) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.flex-table {
  flex: 1;
}

.pagination-fixed {
  margin-top: 8px;
}

/* 合同对话框中的用户选择器样式 */
.user-selector-container {
  width: 100%;
}

.user-selector-container .selected-users {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  min-height: 20px;
}

.user-selector-container .el-button {
  width: 100%;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .user-selector-container .selected-users {
    max-height: 80px;
    overflow-y: auto;
  }
}
</style>
